package 题目集.贪心.排序模拟;// package acm.pta11;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.StringTokenizer;

//https://pintia.cn/problem-sets/1744288973314506752/exam/problems/1744289010547331083?type=7&page=0
public class 网红点打卡攻略 {
    static int[][] map;
    //    static int[][] floyd;
    static int cost = Integer.MAX_VALUE;
    static int index = 0;
    static int count=0;

    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        map = new int[n + 1][n + 1];
        while (m-- > 0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int v = sc.nextInt();
            map[a][b] = v;
            map[b][a] = v;
        }
        int len = sc.nextInt();
        for (int i = 1; i <= len; i++) {
            int k = sc.nextInt();
            if (k != n){
                sc.clear();
                continue;
            }
            Set<Integer> set=new LinkedHashSet<>();
            int last=0;
            for (int j = 0; j < k; j++) {
                last = sc.nextInt();
                set.add(last);
            }
            if (set.size()!=n||map[last][0]==0) continue;
            int money = money(set);
            if (money==Integer.MAX_VALUE)continue;
            count++;
            if (money<cost){
                index=i;
                cost=money;
            }
        }
        System.out.println(count);
        System.out.println(index+" "+cost);
    }

    //    public static int[][] floyd(){
//
//    }
    public static int money(Set<Integer> set) {
        int from = 0;
        int cot = 0;
        for (Integer to : set) {
            if (map[from][to] == 0) return Integer.MAX_VALUE;
            cot += map[from][to];
            from = to;
        }
        if (map[from][0] == 0) return Integer.MAX_VALUE;
        cot += map[from][0];
        return cot;
    }
    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}

